FROM ubuntu:22.04

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y \
  curl git sudo build-essential zlib1g-dev libffi-dev libssl-dev \
  libbz2-dev libreadline-dev libsqlite3-dev libncursesw5-dev xz-utils \
  tzdata gosu ca-certificates

# 创建默认用户（entrypoint.sh 会动态创建实际用户）
ARG USERNAME=dev
ARG USER_UID=1000
ARG USER_GID=1000

# 创建默认用户组和用户（作为模板）
RUN groupadd -g $USER_GID $USERNAME && \
    useradd -m -u $USER_UID -g $USER_GID -s /bin/bash $USERNAME && \
    echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

# 复制初始化脚本到默认用户家目录（作为模板）
COPY init.sh /home/dev/init.sh
RUN chmod +x /home/dev/init.sh && chown dev:dev /home/dev/init.sh

# 复制入口脚本
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh

ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD []